package com.nineclock.approve.nodeResolver;

import cn.hutool.json.JSONObject;
import com.nineclock.approve.utils.ActivitiUtils;
import com.nineclock.common.utils.UUIDUtils;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.SequenceFlow;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
public abstract class ProcessNodeResolver {

    /**
     * 添加节点到流程Process中
     * @param process
     * @param currNode
     * @param nextNode
     */
    public abstract void addFlowNodeToActiviti(Process process, JSONObject currNode, JSONObject nextNode);

    /**
     * 获取当前节点的Key/ID
     * @param currNode
     * @return
     */
    protected String getNodeId(JSONObject currNode) {
        String type = currNode.getStr("type");
        String nodekey = currNode.getStr("nodeKey");
        return ActivitiUtils.getKey(type,nodekey);
    }

    protected void addSequenceFlow(Process process, JSONObject currNode, JSONObject nextNode) {
        //绘制连线
        SequenceFlow sf = new SequenceFlow();
        sf.setId(ActivitiUtils.getKey("seq", UUIDUtils.getUUID()));
        sf.setSourceRef(getNodeId(currNode)); //源节点id
        sf.setTargetRef(getNodeId(nextNode));

        //添加连线到 流程中
        process.addFlowElement(sf);
    }
}
